<?php
	require_once( 'core_DataBaseConnect.php' );
	require_once( 'core_ErrorCode.php' );
	require_once( 'core_Response.php' );
	require_once( 'core_FileManager.php' );
	require_once( 'dao_MemberDAO.php' );
	require_once( 'dao_FreeBoardDAO.php' );
	require_once( '_configs.php' );
	
	function func( $con, $post, $returnType )
	{
		$login_member_id 	= $post[ 'login_member_id' ];
		// 0. 작성 권한 설정 ( 모든 권한, 회원 )
		if( MemberDAO::isAccessable( $con, $login_member_id, array( configs::AUTHOR_ADMIN, configs::AUTHOR_MANAGER, configs::AUTHOR_MEMBER ) ) == false )
		{
			// 작성권한 없음
			return Response::FAIL( ErrorCode::FAIL_WRITE_AUTHOR, "작성권한이 없습니다. 가입된 계정된 가능합니다.", $returnType );
		}
		
		// 1. 게시물 입력
		FreeBoardDAO::insertBoard( $con, $login_member_id, $post[ 'title' ], $post[ 'desc' ] );
		
		$board_seq = $con->insert_id();
		
		// 6. MODEL THUMBS 저장 및 DB 업데이트
		$result 	= FileManager::uploadMultiFiles( configs::FILEUPLOAD_PATH.configs::FILEUPLOAD_FREEBOARDFOLDER."$board_seq/", 'IMAGE_', $_FILES[ 'thumbs' ] );
		$thumbPaths	= array();
		if( count( $result ) > 0 )
		{
			foreach( $result as $k=>$v )
			{
				$thumbPath = substr( $v, strlen( configs::FILEUPLOAD_PATH ) );
				array_push( $thumbPaths, $thumbPath );	// 배열에 담기
			}
	
		}else{
			
		}
		$result	= FreeBoardDAO::insertBoardThumbs( $con, $board_seq, $thumbPaths );
		
		// 7. 응답값 전송
		return Response::SUCCESS( $resonse, $returnType );
	}
?>